package com.prime.tutorial.moviestore.view.customer;

import com.prime.tutorial.moviestore.Constants;
import com.prime.tutorial.moviestore.domain.Customers;
import com.prime.tutorial.moviestore.service.customer.CustomerService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.faces.context.FacesContext;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: vasylja
 * Date: May 8, 2010
 * Time: 10:00:18 PM
 *
 * @author vasylja
 */

@Component("listBalanceChanges")
@Scope("request")
public class ListBalanceChanges {
    private CustomerService customerService;
    private Customers customer;

    public ListBalanceChanges(CustomerService customerService) {
        this.setCustomerService(customerService);
        FacesContext context=FacesContext.getCurrentInstance();
        setCustomer((Customers)(context.getExternalContext().getSessionMap().get(Constants.CUSTOMER_SESSION_KEY)));

    }

    public List getListPayments(){
        return getCustomerService().getAllPaymentsForCustomer(getCustomer());
    }

    public List getListRates(){
        return getCustomerService().getAllRatesForCustomer(getCustomer());
    }

    public int getBalance(){
        return getCustomer().getBalance();
    }

    public CustomerService getCustomerService() {
        return customerService;
    }

    public void setCustomerService(CustomerService customerService) {
        this.customerService = customerService;
    }

    public Customers getCustomer() {
        return customer;
    }

    public void setCustomer(Customers customer) {
        this.customer = customer;
    }
}
